﻿using System.Windows.Forms;
using Nuwanda.Common;
using Microsoft.TeamFoundation.WorkItemTracking.Controls;
using Nuwanda.TfsSpotlight.Shell;
using Nuwanda.TfsSpotlight.Shell.Services.Interfaces;
using StructureMap;

namespace Nuwanda.TfsSpotlight.Views.WorkItems
{
    [Author("Bartłomiej Legiędź")]
    [Pluggable("WorkItemView")]
    public partial class WorkItemView : BaseUserControl, IWorkItemView
    {
        private WorkItemFormControl _workItemControl;
        private readonly ControlInvoker _invoker;

        private ILogger Logger { get; set; }
        private IMonitService MonitService { get; set; }

        public ControlInvoker Invoker
        {
            get { return _invoker; }
        }

        public WorkItemView(ILogger logger, IMonitService monitService)
        {
            InitializeComponent();
            this._invoker = new ControlInvoker(this);
            this.Logger = logger;
            this.MonitService = monitService;
        }

        public WorkItemFormControl GetWorkItemControl()
        {
            return this.Invoker.RunAndReturnInControlsThread(
                delegate
                {
                        if (this._workItemControl == null)
                        {
                            this._workItemControl = new WorkItemFormControl();
                            this._workItemControl.Dock = DockStyle.Fill;
                            this.pnlContent.Controls.Add(this._workItemControl);
                        }

                        return this._workItemControl;
                });
        }

        public void SetCaption(string caption)
        {
            this.Invoker.RunInControlsThread(delegate { this.khHeader.Values.Heading = caption; });
        }

        public void Disable()
        {
            this.Invoker.RunInControlsThread(delegate { this.Enabled = false; });
        }

        public void Enable()
        {
            this.Invoker.RunInControlsThread(delegate { this.Enabled = true; });
        }
    }
}